package com.wang.test;

public class TicketTest2 extends Thread{
	private static int num = 50;
//	private static Object key = new Object();
	@Override
	public void run() {
		while(num > 0){
			sellTicket();
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public TicketTest2() {
		super();
	}

	public TicketTest2(String name) {
		super(name);
	}

	public void sellTicket(){
		synchronized (this.getClass()) {
			if (num > 0) {	
				System.out.println(Thread.currentThread().getName()+"当前票："+num--);
			}
		}
	}
}
